<template>
  <div>
     <Row>
        <input v-model="uid" placeholder="uid" ></input>
        <input v-model="bussiness" placeholder="渠道号" ></input>
        <Date-picker v-model="startDay" placeholder="开始日期" format="yyyy-MM-dd"></Date-picker>
        <Date-picker v-model="endDay" placeholder="结束日期" format="yyyy-MM-dd"></Date-picker>
        <Button type="primary" @click="onSearch">查询</Button>
        <label >总充值金额:{{totalAmount}},</label>
        <label >总获得金币:{{totalPoints}}</label>
    </Row>
    <Table :border="true" :stripe="true" :show-header="true" :data="tableData" :columns="tableColumns"></Table>
    <Page class="bottom-page" :total="totalPage" :current="crtPage" :page-size="pageSize" show-total show-elevator @on-change="onChange"></Page>
  </div>
</template>
<script>

import {getDayAnalys} from '@/api/recharge.js'
import {getVO} from '@/common/proto-vo.js'
export default {
  data () {
    return {
      tableData: [],
      startDay: '',
      endDay: '',
      uid: '',
      bussiness: '',
      crtPage: 1,
      totalPage: 0,
      pageSize: 10,
      totalPoints: 0,
      totalAmount: 0
    }
  },
  created () {
    this.endDay = new Date()
    this.startDay = new Date().setDate(new Date().getDate() - 7)
    this.onSearch()
  },
  methods: {
    onSearch () {
      let sSendDay = 0
      let eSendDay = 0
      if (this.startDay !== '' && this.endDay !== '') {
        let sDay = new Date(this.startDay)
        let eDay = new Date(this.endDay)
        // sSendDay = '' + sDay.getFullYear() + ((sDay.getMonth() + 1) < 10 ? '0' + (sDay.getMonth() + 1) : (sDay.getMonth() + 1)) + (sDay.getDate() < 10 ? '0' + sDay.getDate() : sDay.getDate())
        // eSendDay = '' + eDay.getFullYear() + ((eDay.getMonth() + 1) < 10 ? '0' + (eDay.getMonth() + 1) : (eDay.getMonth() + 1)) + (eDay.getDate() < 10 ? '0' + eDay.getDate() : eDay.getDate())
        // sSendDay = parseInt(sSendDay)
        // eSendDay = parseInt(eSendDay)
        sSendDay = sDay.getTime()
        eSendDay = eDay.getTime()
      }

      let tUid = 0
      if (this.uid !== '') {
        tUid = Number(this.uid)
      }

      console.log('sSendDay:', sSendDay, ',eSendDay:', eSendDay, ',bussiness:', this.bussiness)
      getDayAnalys(this.crtPage, this.pageSize, sSendDay, eSendDay, this.bussiness, tUid).then((data) => {
        if (!data) {
          return
        }
        this.tableData = []
        let RechargeLogVO = getVO('RechargeLogVO')
        let pv = data.data.data
        let len = pv.data.length
        for (let i = 0; i < len; i++) {
          let vo = RechargeLogVO.decode(pv.data[i])
          vo.rechargeID = vo.rechargeID.toNumber()
          vo.id = vo.id.toNumber()
          this.tableData.push(vo)
        }
        this.totalPage = pv.intValues[1]
        let points = data.data.data.longValues[1]
        let amount = data.data.data.longValues[0]
        this.totalPoints = points.toNumber()
        this.totalAmount = amount.toNumber()
        console.log(this.tableData)
      })
    },
    onChange (item) {
      console.log(item)
      this.crtPage = item
      this.onSearch()
    }
  },
  computed: {
    tableColumns () {
      let cols = [
        {
          title: '时间',
          key: 'strCreateTime',
          align: 'center'
        },
        {
          title: 'id',
          key: 'id',
          align: 'center'
        },
        {
          title: '名字',
          key: 'userName',
          align: 'center'
        },
        {
          title: 'productId',
          key: 'productId',
          align: 'center'
        },
        {
          title: 'sdkOrderId',
          key: 'sdkOrderId',
          align: 'center'
        },
        {
          title: '充值量',
          key: 'amount',
          align: 'center'
        },
        {
          title: '获得金币',
          key: 'points',
          align: 'center'
        },
        {
          title: '渠道号',
          key: 'gameOperator',
          align: 'center'
        }
      ]
      return cols
    }
  }
}

</script>

<style scoped>
.log-str{
  font-size: 14px;
  margin-bottom: 2px;
}
.content{
  min-height: 460px;
}
.bottom-page{
  margin-top: 5px;
  margin-bottom: 10px;
  float: right;
}
</style>
